//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "FloorTruncation.h"
using namespace Cephei::QL::Math;
#include <gen/QL/Math/Rounding.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::CFloorTruncation::CFloorTruncation (Int32 precision, Microsoft::FSharp::Core::FSharpOption<Int32>^ digit) : CRounding(CFloorTruncation::typeid)
{
    try
    {
#ifdef HANDLE
        _phFloorTruncation = NULL;
#endif
        QuantLib::Integer _precision = (QuantLib::Integer)ValueHelper::Convert (precision);
        QuantLib::Integer _digit = 
            (Microsoft::FSharp::Core::FSharpOption<Int32>::IsSome::get (digit) ? (QuantLib::Integer)ValueHelper::Convert (digit->Value) : 5); //4
        _ppFloorTruncation = new boost::shared_ptr<QuantLib::FloorTruncation> (new QuantLib::FloorTruncation ( _precision,  _digit ));
        SetRounding (boost::dynamic_pointer_cast<QuantLib::Rounding> (*_ppFloorTruncation));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Math::CFloorTruncation::CFloorTruncation (boost::shared_ptr<QuantLib::FloorTruncation>& childNative, Object^ owner) : CRounding(CFloorTruncation::typeid)
{
#ifdef HANDLE
	_phFloorTruncation = NULL;
#endif
	_ppFloorTruncation = &childNative;
    _ppRounding = new boost::shared_ptr<QuantLib::Rounding> (boost::dynamic_pointer_cast<QuantLib::Rounding> (*_ppFloorTruncation));
}
Cephei::QL::Math::CFloorTruncation::CFloorTruncation (QuantLib::FloorTruncation& childNative, Object^ owner) : CRounding(CFloorTruncation::typeid)
{
#ifdef HANDLE
	_phFloorTruncation = NULL;
#endif
	_ppFloorTruncation = new boost::shared_ptr<QuantLib::FloorTruncation> (&childNative);
    _ppRounding = new boost::shared_ptr<QuantLib::Rounding> (boost::dynamic_pointer_cast<QuantLib::Rounding> (*_ppFloorTruncation));
    _FloorTruncationOwner = owner;
    _RoundingOwner = owner;
}

Cephei::QL::Math::CFloorTruncation::CFloorTruncation (CFloorTruncation^ copy) : CRounding(CFloorTruncation::typeid)
{
#ifdef HANDLE
	_phFloorTruncation = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppFloorTruncation = new boost::shared_ptr<QuantLib::FloorTruncation> (copy->GetShared());
        _ppRounding = new boost::shared_ptr<QuantLib::Rounding> (boost::dynamic_pointer_cast<QuantLib::Rounding> (*_ppFloorTruncation));
    }
}
Cephei::QL::Math::CFloorTruncation::CFloorTruncation (System::Type^ t) : CRounding(CFloorTruncation::typeid)
{
#ifdef HANDLE
	_phFloorTruncation = NULL;
#endif
	if (!t->IsSubclassOf(CFloorTruncation::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::CFloorTruncation::CFloorTruncation (QuantLib::Handle<QuantLib::FloorTruncation>& childNative, Object^ owner)  : CRounding(CFloorTruncation::typeid)
{
	_phFloorTruncation = &childNative;
	_ppFloorTruncation = &static_cast<boost::shared_ptr<QuantLib::FloorTruncation>>(childNative.currentLink());
    _ppRounding = new boost::shared_ptr<QuantLib::Rounding> (boost::dynamic_pointer_cast<QuantLib::Rounding> (*_ppFloorTruncation));
    _FloorTruncationOwner = owner;
}
Cephei::QL::Math::CFloorTruncation::CFloorTruncation (QuantLib::Handle<QuantLib::FloorTruncation> childNative)  : CRounding(CFloorTruncation::typeid)
{
	_phFloorTruncation = &childNative;
	_ppFloorTruncation = &static_cast<boost::shared_ptr<QuantLib::FloorTruncation>>(childNative.currentLink());
    _ppRounding = new boost::shared_ptr<QuantLib::Rounding> (boost::dynamic_pointer_cast<QuantLib::Rounding> (*_ppFloorTruncation));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::CFloorTruncation::CFloorTruncation (QuantLib::FloorTruncation childNative)  : CRounding(CFloorTruncation::typeid)
{
#ifdef HANDLE
	_phFloorTruncation = NULL;
#endif
	_ppFloorTruncation = new boost::shared_ptr<QuantLib::FloorTruncation> (new QuantLib::FloorTruncation (childNative));
    _ppRounding = new boost::shared_ptr<QuantLib::Rounding> (boost::dynamic_pointer_cast<QuantLib::Rounding> (*_ppFloorTruncation));
}
#endif

Cephei::QL::Math::CFloorTruncation::~CFloorTruncation ()
{
    if (_ppFloorTruncation != NULL)
    {
	    delete _ppFloorTruncation;
        _ppFloorTruncation = NULL;
    }
}
Cephei::QL::Math::CFloorTruncation::!CFloorTruncation ()
{
    if (_ppFloorTruncation != NULL)
    {
	    delete _ppFloorTruncation;
    }
}
QuantLib::FloorTruncation& Cephei::QL::Math::CFloorTruncation::GetReference ()
{
    if (_ppFloorTruncation == NULL) throw gcnew NativeNullException ();
	return **_ppFloorTruncation;
}
boost::shared_ptr<QuantLib::FloorTruncation>& Cephei::QL::Math::CFloorTruncation::GetShared ()
{
    if (_ppFloorTruncation == NULL) throw gcnew NativeNullException ();
	return *_ppFloorTruncation;
}
QuantLib::FloorTruncation* Cephei::QL::Math::CFloorTruncation::GetPointer ()
{
    if (_ppFloorTruncation == NULL) throw gcnew NativeNullException ();
	return &**_ppFloorTruncation;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::FloorTruncation>& Cephei::QL::Math::CFloorTruncation::GetHandle ()
{
	if (_phFloorTruncation == NULL)
	{
		_phFloorTruncation = new Handle<QuantLib::FloorTruncation> (*_ppFloorTruncation);
	}
	return *_phFloorTruncation;
}
#endif
bool Cephei::QL::Math::CFloorTruncation::HasNative () 
{
	return (_ppFloorTruncation != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Math::IFloorTruncation^ Cephei::QL::Math::CFloorTruncation_Factory::Create (Int32 precision, Microsoft::FSharp::Core::FSharpOption<Int32>^ digit)
{
    return gcnew CFloorTruncation ( precision,  digit);
}
